class up extends eui.Component implements  eui.UIComponent {
	new:eui.Button
	open:eui.Button
	save:eui.Button
	choose:eui.Button
	move:eui.Button
	scal:eui.Button
    rota:eui.Button
	deletebutton:eui.Button
	runbutton:eui.Button
	clearbutton:eui.Button
	rungameswitch:boolean=false

	
	public constructor() {
		super();
	}

	protected partAdded(partName:string,instance:any):void
	{
		super.partAdded(partName,instance);
	}


	protected childrenCreated():void
	{
		super.childrenCreated();
		this.beginlisten();
		this.runbutton.addEventListener(egret.TouchEvent.TOUCH_TAP,this.rungame,this);
	}
	private rungame()
	{
		if(ASSIST.getASSIST.player==undefined)return;
		this.rungameswitch=!this.rungameswitch
		if(this.rungameswitch)
	    {
		  this.runbutton.label="停止"
		  CMainEditor.editor.rungamebegin();
		  ASSIST.getASSIST.loadbeginpos();
		  TIMERUP.gettimercontrl.timerbegin();
		  TIMERUP.gettimercontrl.touchbegin();
		}
		else 
		{
			this.runbutton.label="运行"
			
			TIMERUP.gettimercontrl.touchstop();
			TIMERUP.gettimercontrl.timerstop();
			ASSIST.getASSIST.resetbeginpos();
			CMainEditor.editor.rungameend();
			
		}
		
	}
	private newplatte()
	{
		CMainEditor.editor.newmedimplatte();
	}
	private moveobject(e:egret.TouchEvent)
	{
		if(CCollitionEditor.editor.state)
		{
			if(CCollitionEditor.editor.goal!=undefined)
			CCollitionEditor.editor.movecollition();
		}
		else if(CMainEditor.editor.goal!=undefined)
		{
			CObjectEditor.editor.moveobject();
		}
	
	}
	private chooseer(e:egret.TouchEvent)
	{
		
		if(CCollitionEditor.editor.state)
		{
			if(CCollitionEditor.editor.goal!=undefined)
			CCollitionEditor.editor.choosecollition();
		}
		else if(CMainEditor.editor.goal!=undefined)
		{
			CObjectEditor.editor.chooseobject();
		}
	}
	private deletes(e:egret.TouchEvent)
	{
        if(CCollitionEditor.editor.state)
		{
			if(CCollitionEditor.editor.goal!=undefined)
			CCollitionEditor.editor.collitiondeletes();
		}
		else if(CMainEditor.editor.goal!=undefined)
		{
			CMainEditor.editor.objctdeletes();
		}
	}
	private rotaObject(e:egret.TouchEvent)
	{
		 if(CCollitionEditor.editor.state)
		{
			return;
		}
		else if(CMainEditor.editor.goal!=undefined)
		{
            CObjectEditor.editor.rotaobject();
		}
	}
	private scalobject(e:egret.TouchEvent)
	{
        if(CCollitionEditor.editor.state)
		{
			if(CCollitionEditor.editor.goal!=undefined)
			CCollitionEditor.editor.scalcollition();
		}
		else if(CMainEditor.editor.goal!=undefined)
		{
			CObjectEditor.editor.scalobject();
		}
       
	}
	private savegame()
	{
       CMainEditor.editor.opensaveopendelete(saveopendeletemode.save)
		
	}
	private opengame()
	{

	   CMainEditor.editor.opensaveopendelete(saveopendeletemode.open)
	}
	private clear()
	{
		CMainEditor.editor.opensaveopendelete(saveopendeletemode.delete)
	}
	public beginlisten()
	{
		this.new.addEventListener(egret.TouchEvent.TOUCH_TAP,this.newplatte,this);
		this.move.addEventListener(egret.TouchEvent.TOUCH_TAP,this.moveobject,this);
		this.scal.addEventListener(egret.TouchEvent.TOUCH_TAP,this.scalobject,this);
		this.choose.addEventListener(egret.TouchEvent.TOUCH_TAP,this.chooseer,this);
		this.rota.addEventListener(egret.TouchEvent.TOUCH_TAP,this.rotaObject,this);
		this.deletebutton.addEventListener(egret.TouchEvent.TOUCH_TAP,this.deletes,this);
		this.save.addEventListener(egret.TouchEvent.TOUCH_TAP,this.savegame,this);
		this.open.addEventListener(egret.TouchEvent.TOUCH_TAP,this.opengame,this);
		this.clearbutton.addEventListener(egret.TouchEvent.TOUCH_TAP,this.clear,this);
	}
	public stoplisten()
	{
		this.new.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.newplatte,this);
		this.move.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.moveobject,this);
		this.scal.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.scalobject,this);
		this.choose.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.chooseer,this)
		this.rota.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.rotaObject,this);
		this.deletebutton.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.deletes,this);
		this.save.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.savegame,this);
		this.open.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.opengame,this);
		this.clearbutton.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.clear,this);
	}
	
}